import math
import numpy as np
import time
import os
import random
import csv
import cmath
import matplotlib.pyplot as plt
import csvtest
import matplotlib as mpl

# print(math.atan(90/120) / math.pi * 180)
# print(math.atan(100/120) / math.pi * 180)
data = csvtest.Read_csv_inrows(r'CASE1_FI\Test_Case2_90.csv', range(3))
# data = csvtest.Read_csv_inrows(r'LESE\Case1_0416_0.csv', range(3))
thaa_deg = 0
thaa = thaa_deg / 180 * math.pi
print(thaa_deg, math.asin(math.sin(thaa) - 0.096) / math.pi * 180, math.asin(math.sin(thaa) + 0.096) / math.pi * 180)
print(thaa_deg, math.asin(math.sin(thaa) - 0.035) / math.pi * 180, math.asin(math.sin(thaa) + 0.035) / math.pi * 180)
print(thaa_deg, math.asin(math.sin(thaa) - 0.021) / math.pi * 180, math.asin(math.sin(thaa) + 0.021) / math.pi * 180)

print(thaa_deg, math.asin(math.sin(thaa) - 0.021) / math.pi * 180, math.asin(math.sin(thaa) + 0.021) / math.pi * 180)

phaa, thee = 361, 451
Z = np.zeros((phaa, thee))
for i in range(phaa):
    for j in range(thee):
        Z[i, j] = data[thee * i + j, 2]

Z = Z - np.max(Z)
# Z[Z<-35] = -35
print(np.shape(Z))
X, Y = np.indices([phaa, thee])
X = X/360*math.pi*2
Y = Y/5 / 180 * math.pi
Y = np.sin(Y)

print("1 3: ", Z[0, 150], Z[90, 150], Z[180, 150], Z[270, 150])
print("2 4: ", Z[0, 150], Z[100, 125], Z[200, 225], Z[280, 175])

fDct = {"contour": plt.contour, "contourf": plt.contourf, "pcolormesh": plt.pcolormesh}
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(1, 1, 1, projection='polar')

# lvls = np.arange(-35, 0.1, 5)
lvls = np.array([ -35, -30, -25, -20, -15, -10, -5, -3, 0])
# lvls = np.arange(-36, 0.1, 2)
cset = plt.contourf(X, Y, Z, lvls, cmap=mpl.cm.jet)
# contour = plt.contour(X, Y, Z, lvls, colors='k', )
# plt.clabel(contour, fontsize=10, colors='k')
plt.colorbar(cset)
plt.tight_layout()
ax.grid(False)          # 关闭网格线
ax.set_xticklabels([])  # 隐藏角度刻度标签
ax.set_yticklabels([])  # 隐藏半径刻度标签
plt.show()
